public class Calculator {

    private static int result;

    public void add(int n) {
        result = result + n;
    }

    public void subtract(int n) {
        result = result - n;
    }

    public void multiply(int n) {
        result = result * n;
    }

    public void divide(int n) {
        if (n == 0) {
            throw new IllegalArgumentException("除数不能为零");
        }
        result = result / n;
    }

    public void square() {
        result = result * result;
    }

    public int getResult() {
        return result;
    }

    public void clear() {
        result = 0;
    }
}
